﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using Baimasoft.FrameWork.Base;
using Baimasoft.Manage.SqlServerDAL;

public partial class BBS_BbsManage_ReManageEdit : Baimasoft.Web.UI.PageFormTop 
{
    CMods MyCM = new CMods();
    Articles MyAT = new Articles();
    Replies MyRL = new Replies();

    protected override void InitForm()
    {
        if (!Page.IsPostBack)
        {
            try
            {
                string sEditStatus = this.Request.QueryString["EditStatus"].ToString().Trim();
                if (sEditStatus == "2")
                {
                    string sID = this.Request.QueryString["ID"].ToString().Trim();
                    SqlDataReader MySDR = MyRL.ReadRepliesInfos("a.RepliesID =" + sID);
                    if (MySDR.Read())
                    {
                        SectionName.Text = MySDR["sectionname"].ToString().Trim();
                        HSectionID.Value = MySDR["SectionID"].ToString().Trim();

                        Title.Text = MySDR["Title"].ToString().Trim();
                        HArticleID.Value = MySDR["ArticleID"].ToString().Trim();
                        SectionName.Text = MySDR["sectionname"].ToString().Trim();
                        RePerson.Text = MySDR["RePerson"].ToString().Trim();

                        ReDT.Text = MySDR["ReDT"].ToString().Trim();
                        
                        sApproveResultDrp.Text = MySDR["sApproveResult"].ToString().Trim();
                        Content.Text = MySDR["Content"].ToString().Trim();
                    }
                }
            }
            catch
            {
            }
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string sSectionID =HSectionID .Value .ToString ().Trim ();
        string sArticleID = HArticleID .Value .ToString ().Trim ();
        string sRePerson = RePerson.Text.ToString().Trim();
        string sReDT = ReDT.Text.ToString().Trim();
       
        int ssApproveResultDrp = int.Parse(sApproveResultDrp.SelectedValue.ToString().Trim());
        string sContent = Content.Text.ToString().Trim();

        string UserIP = Request.UserHostAddress;
        string UserDNS = Request.UserHostName;

        if (this.EditStatus == EditStatus.Add)
        {
            int iback = MyRL.AddReplies(sSectionID, sArticleID, sContent,"", UserIP, sRePerson, UserDNS, ssApproveResultDrp);
            if (iback > 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存成功!');window.location.href='ReManageList.aspx';</script>");
                return;
            }
        }
        else
        {
            DateTime UpDt = DateTime.Now;
            int iback = MyRL .UpdateReplies(sSectionID, sArticleID, sContent, "",UserIP, sRePerson, UserDNS, ssApproveResultDrp,this.Request.QueryString["ID"].ToString().Trim());
            if (iback > 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');window.location.href='ReManageList.aspx';</script>");
                return;
            }
        }
    }
}
